import Vue from "vue";

import { updateData } from "../localStorage";

export default {
  //设置用户信息
  setUserInfo(state, data) {
    for (let name of Object.keys(data)) {
      Vue.set(state.userInfo, name, data[name]);
    }
  },

  //同步vuex数据至localstorage
  syncData(state) {
    updateData(state);
  },
  //同步state
  syncState(state) {
    Vue.set(state, "userInfo", JSON.parse(localStorage.userInfo));
    Vue.set(state, "identify", JSON.parse(localStorage.identify));
  },

  //退出登录
  logout(state) {
    Vue.set(state, "userInfo", {});
    localStorage.removeItem("library_sys_token");
  },

  //设置身份标识
  setIdentify(state, id) {
    Vue.set(state, "identify", id);
  },
  //设置操作提醒
  setNotice(state, notice) {
    Vue.set(state, "notice", notice);
  },
};
